package nl.haemers.data.collections 
{
	import flash.utils.Dictionary;
	import nl.haemers.utils.Logger;
	/**
	 * ...
	 * @author Jonathan Haemers
	 */
	public class List implements IList
	{
		private var _dict					:Dictionary;
		private var _size					:int;
		//TODO create specific type list
		private var _type					:Class;
		
		private var _overwriteAble			:Boolean;
		
		public function List() 
		{
			_dict = new Dictionary();
			//_type = type;
			_size = 0;
		}		
		
		/** Public methods **/
		public function add(key:String, e:Object) : Boolean
		{
			var excists:Boolean = hasKey(key);
			if (!excists || _overwriteAble)
			{				
				if (!excists)
					_size++;
					
				_dict[key] = e;
				return true;
			}
			throw new Error("Duplicated key: " + key + " value: " + e + " dict value: " + _dict[key]);
			return false;
		}
		
		public function search(key:String) : Object
		{
			return _dict[key];
		}
		
		public function hasKey(key:String) : Boolean
		{
			return _dict[key] != null;
		}		
		
		public function hasObject(e:Object) : Boolean
		{
			trace("not yet implemented");
			return false;
		}
		
		public function remove(key:String) : Boolean
		{
			if (_size > 0)
			{
				if (hasKey(key))
				{
					delete _dict[key];
					_size--;
					
					return true;
				}
			}
			return false;
		}
		
		public function clear() : void
		{
			for each(var key:String in _dict)
			{
				delete _dict[key];
			}
			_dict = new Dictionary();
			_size = 0;
		}
		
		/** Getters & Setters **/
		public function get overwriteAble() : Boolean
		{
			return _overwriteAble;
		}
		public function set overwriteAble(value:Boolean) : void 
		{
			_overwriteAble = value;
		}
		
		public function get size() : int
		{
			return _size;
		}
		
		public function get items() : Dictionary
		{
			var _copy:Dictionary = new Dictionary();
			for(var key:String in _dict)
			{
				_copy[key] = _dict[key];
			}
			return _copy;
		}
		/** Protected methods **/
		
		/** Private methods **/
		
	}

}